<?php if (!defined('THINK_PATH')) exit();?><!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>挂号退款-业务审核</title>
    <link rel="stylesheet" type="text/css" href="__PUBLIC__/easyui/themes/default/easyui.css">
<link rel="stylesheet" type="text/css" href="__PUBLIC__/easyui/themes/icon.css">
<script type="text/javascript" src="__PUBLIC__/easyui/jquery.min.js"></script>
<script type="text/javascript" src="__PUBLIC__/easyui/jquery.easyui.min.js"></script>
<script type="text/javascript" src="__PUBLIC__/easyui/locale/easyui-lang-zh_CN.js"></script>
<script type="text/javascript" src="__PUBLIC__/js/easyui_common.js"></script>

    <script type="text/javascript" src="__PUBLIC__/layer/layer.js"></script>
    <style>
        .calendar-disabled{background: #eeeeee;color: #666666;border-radius: 0px}
    </style>
</head>
<body>
<div id="tb" style="padding:5px;height:auto;">
    <div style="margin: 10px 0 10px 10px" >
        <!-- form表单 指定id和name之后会自动带到服务器 -->
        <form name="searchform" method="get" action="" id ="searchform" style="height:auto;margin-bottom: 20px; line-height: 40px">

            <label for="time_frame">时间范围：</label>
            <select class="easyui-combobox" id ="time_frame" name="time_frame" style="width:140px;height:32px;">
                <option value="3">支付时间</option>
                <option value="4" selected="selected">申请退款时间</option>
                <option value="5">审批退款时间</option>
            </select>
            <input type="datetime" value="<?php echo ($timeFor); ?>" name="time_for" id="time_for" style="width:140px;height:32px">
            <label>至</label>
            <input style="width:140px;height:32px" value="<?php echo ($timeTo); ?>" type="datetime" name="time_to" id="time_to">
            <br/>
            <label for="pay_state">订单状态：</label>
            <select class="easyui-combobox" id ="pay_state" name="pay_state" style="width:140px;height:32px;">
                <option value="10">待业务审批</option>
                <option value="11">待财务审批</option>
                <option value="12">业务拒绝退款</option>
                <option value="13">财务拒绝退款</option>
                <option value="14">退款中</option>
                <option value="6">退款成功</option>
                <option value="7">退款失败</option>
            </select>
            <label for="order_id">订单搜索：</label>
            <input class="easyui-textbox" id="order_id" name="order_id" data-options="prompt:'请输入订单号'" style="width:140px;height:32px"/>
            <input type="hidden" name="advanced" value="1" id="advanced">
            <a href="javascript:void(0);" id="submit_search" class="easyui-linkbutton" iconCls="icon-search"  style="width:60px;height:32px">查询</a>&nbsp;&nbsp;
        </form>
    </div>
</div>
<table id="dg"  style="width:100%; min-height: 600px;"  title="查询结果"
       data-options="rownumbers:false,
			singleSelect:true,
			pagination:true,
			ctrlSelect:true,
			fitColumns:true,
			loadMsg:'正在加载,请等待....',
			url:'__URL__/getRefundReportsList',
			method:'post',
			toolbar:'#tb',
			">
    <thead>
    <tr>
        <th data-options="field:'order_id',align:'center',width:'10px'">订单号</th>
        <th data-options="field:'reason',align:'center',width:'20px'">退款原因</th>
        <th data-options="field:'reg_fee',formatter:formatRegisterFee,align:'center',width:'10px'">挂号费</th>
        <th data-options="field:'service_fee',formatter:formatRegisterFee,align:'center',width:'10px'">服务费</th>
        <th data-options="field:'pay_dt',align:'center',width:'10px'">支付时间</th>
        <th data-options="field:'pay_type',align:'center',width:'10px'">支付渠道</th>
        <th data-options="field:'pay_no',align:'center',width:'10px'">支付流水号</th>
        <th data-options="field:'refund_create_dt',align:'center',width:'10px'">申请退款时间</th>
        <th data-options="field:'refund_approve_dt',align:'center',width:'10px'">审批退款时间</th>
        <th data-options="field:'op',formatter:formatOperation,align:'center',width:'20px'">操作</th>
    </tr>
    </thead>
</table>
<script type="text/javascript">
    var height = document.documentElement.clientHeight;
    height = height - 30;
    $("#dg").css("height",height+"px");
    ///统计
    function total() {
        var rows = $('#dg').datagrid('getRows');
        var num = rows.length;
        if(num > 0) {
            $('#dg').datagrid('deleteRow', num - 1);
        }
    }
    //价格
    function formatRegisterFee(val,row) {
        val = "￥"+ Number(val).toFixed(2);
        return val;
    }
    function formatRefundApproveDt(val,row) {
        var refundState = row.refund_state;
        val = '';
        if($.inArray(refundState,["2","3"]) != -1){
            val = row.busi_approve_dt;
        }
        if($.inArray(refundState,["4","5","6"]) != -1){
            val = row.fina_approve_dt;
        }
        return val;
    }
    function formatOperation(val,row){
        var permissions = <?php echo ($permissions); ?>;
        var orderId = row.order_id;
        val = "<a href='javascript:void(0);' onclick='orderInfo(\""+orderId+"\")'>订单详情</a>";
        row.refund_state = row.refund_state == '5' ? '2' : row.refund_state;
        switch(row.refund_state){
            case '1':
                if(permissions.refund_business_audit == true){
                    val = val + "&nbsp;<a href='javascript:void(0);' onclick='refundBusinessAudit(\""+row.refund_id+"\")'>同意退款</a>"
                            +"&nbsp;<a href='javascript:void(0);' onclick='refundAudit(\""+row.refund_id+"\",\""+orderId+"\","+row.pay_type_id+",3)'>拒绝退款</a>";
                }
                break;
            case '2':
                if(permissions.refund_financial_audit == true){
                    switch(row.pay_type_id){
                        case "1":
                            val = val + "&nbsp;<a href='javascript:void(0);' onclick='alipayRefund(\""+row.refund_id+"\",\""+orderId+"\",\""+row.pay_no+"\")'>同意退款</a>";
                            break;
                        case "2":
                            val = val + "&nbsp;<a href='javascript:void(0);' onclick='wxPayRefund(\""+row.refund_id+"\",\""+orderId+"\",\""+row.pay_no+"\")'>同意退款</a>";
                            break;
                        case "3":
                            val = val + "&nbsp;<a href='javascript:void(0);' onclick='unionPayRefund()'>同意退款</a>";
                            break;
                        case "4":
                            val = val + "&nbsp;<a href='javascript:void(0);' onclick='wxPayRefund(\""+row.refund_id+"\",\""+orderId+"\",\""+row.pay_no+"\")'>同意退款</a>";
                            break;
                    }
                    val = val +"&nbsp;<a href='javascript:void(0);' onclick='refundAudit(\""+row.refund_id+"\",\""+orderId+"\","+row.pay_type_id+",4)'>拒绝退款</a>";
                }
                break;
            default:
                break;
        }
        return val;
    }
    $(function(){
        $('#time_for,#time_to').datebox().datebox('calendar').calendar({
            validator: function(date){
                var now = new Date();
                var d1 = new Date(now.getFullYear()-1, now.getMonth(), now.getDate()-1);
                return d1 <= date;
            }
        });
        $('#time_to').datebox().datebox('calendar').calendar({
            validator: function(date){
                var now = new Date();
                var d1 = new Date(now.getFullYear()-1, now.getMonth(), now.getDate()-1);
                return d1 <= date;
            }
        });
    });
    ;!function(){
        //加载扩展模块
        layer.config({
            extend: 'extend/layer.ext.js'
        });
    }();
    function orderInfo(order_id){
        layer.open({
            type: 2,
            title: '订单详情',
            fix: false,
            shadeClose: true,
            maxmin: false,
            area: ['500px', '100%'],
            content: ['__URL__/orderInfo/?order_id='+order_id,'yes'],
            end: function(){}
        });
    }
    function refundBusinessAudit(refundId) {
        layer.msg("确定同意退款？", {
            time: 10000, //10s后自动关闭
            btn: ['确定', '取消'],
            yes: function () {
                $.ajax({
                    url: '__URL__/refundBusinessAudit',
                    type: 'post',
                    data: {'refund_id': refundId},
                    cache: false,
                    dataType: 'json',
                    success: function (data) {
                        if (data > 0) {
                            layer.msg('已通过退款审核！');
                            $('#dg').datagrid({queryParams: form2Json("searchform")});
                        } else {
                            layer.msg("请重新审核！");
                        }
                    },
                    error: function () {
                        layer.msg("审核异常");
                    }
                });
            }
        });
    }
    function refundAudit(refundId,orderId,payType,state){
        layer.prompt({
            title: '拒绝退款',
            maxlength:500,
            formType: 2 //prompt风格，支持0-2
        }, function(reason){
            $.ajax( {
                url: '__URL__/refundAudit',
                type: 'post',
                data: {'refund_id':refundId,'state':state,'order_id':orderId,'pay_type':payType,'reason':reason},
                cache:false,
                dataType:'json',
                success: function (data){
                    if(data >0 ){
                        layer.msg("已拒绝退款！");
                        $('#dg').datagrid({ queryParams: form2Json("searchform") });
                    }else{
                        layer.msg("请重新审批！");
                    }
                },
                error: function (){
                    layer.msg("审批异常！");
                }
            });
        });
    }
    function alipayRefund(refundId,orderId,payNo) {
        layer.msg("确定同意退款？", {
            time: 10000, //10s后自动关闭
            btn: ['确定', '取消'],
            yes: function () {
                layer.open({
                    type: 2,
                    title: '支付宝退款',
                    fix: false,
                    shadeClose: true,
                    maxmin: true,
                    area: ['90%', '90%'],
                    content: ['__URL__/orderAliPayRefund/?order_id=' + orderId + '&refund_id=' + refundId + '&pay_no=' + payNo, 'yes'],
                    end: function () {
                        layer.msg("已操作退款？", {
                            time: 10000, //10s后自动关闭
                            btn: ['是', '否'],
                            yes: function () {
                                $.ajax({
                                    url: '__URL__/refundFinancialAudit',
                                    type: 'post',
                                    data: {
                                        'refund_id': refundId,
                                        'order_id': orderId,
                                        'pay_no': payNo,
                                        'pay_type': 1
                                    },
                                    cache: false,
                                    dataType: 'json',
                                    success: function (data) {
                                        if (data > 0) {
                                            layer.msg('已通过退款申请！');
                                            $('#dg').datagrid({queryParams: form2Json("searchform")});
                                        } else {
                                            layer.msg("请重新审批！");
                                        }
                                    },
                                    error: function () {
                                        layer.msg("审批异常");
                                    }
                                });
                            }
                        });
                    }
                });
            }
        })
    }
    function wxPayRefund(refundId,orderId,payNo) {
        layer.msg("确定同意退款？", {
            time: 10000, //10s后自动关闭
            btn: ['确定', '取消'],
            yes: function () {
                $.ajax({
                    url: '__URL__/orderWxPayRefund',
                    type: 'post',
                    data: {'refund_id': refundId, 'order_id': orderId, 'pay_no': payNo},
                    cache: false,
                    dataType: 'json',
                    success: function (data) {
                        if (data > 0) {
                            layer.msg('已通过退款申请！');
                            $('#dg').datagrid({queryParams: form2Json("searchform")});
                        } else {
                            layer.msg("请重新审批！");
                        }
                    },
                    error: function () {
                        layer.msg("系统异常！");
                    }
                });
            }
        })
    }
    function unionPayRefund(){

    }
</script>
</body>
</html>